package model;

import java.io.Serializable;

/**
 * The base model class
 */
public class BaseModelItem implements Serializable {

    private int id;
    private String name;
    private int version = 0;

    public BaseModelItem() {
        id = -1;
        name = null;
    }
    
    /**
     * Constructor for the View
     *
     * @param name name of the object
     */
    public BaseModelItem(String name) {
        this.name = name;
        id = -1;
    }

    /**
     * Constructor for the File System
     *
     * @param id identificator of the object
     * @param name name of the object
     */
    public BaseModelItem(int id, String name) {
        this.id = id;
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String toString() {
        return name;
    }

    public int getVersion() {
        return version;
    }
    
    public void incrementVersion() {
        version++;
    }

    public void setVersion(int version) {
        this.version = version;
    }

    /**
     * Parse the user's query to the regular expression
     *
     * @param parametr user's query
     * @return regular expression
     */
    protected String parseParametr(String parametr) {
        String regex = "";
        for (int i = 0; i < parametr.length(); i++) {
            if (parametr.charAt(i) == '*') {
                regex += ".*";
                continue;
            }
            if (parametr.charAt(i) == '?') {
                regex += ".";
                continue;
            }
            regex += parametr.charAt(i);
        }
        return regex.toLowerCase();
    }
    
}
